<!DOCTYPE html>
<html lang="en">
<head>
    <title>随机密码生成</title>
</head>
<body>
<button onclick="javascript:xdst()" style="background-color:cadetblue;">随机生成9位安全密码</button>
<button onclick="javascript:s()" style="background-color:aliceblue">随机生成6位数字密码</button>
<button ; onclick="javascript:xds()" style="background-color:skyblue">随机生成9位非特密码</button>
<div id="password" style="padding:2px;width: 100px;margin: 2px;"></div>
<script type="text/javascript">
    //去掉Il1,0O,<,支付密码4、76
    var signArray_xdst = [
        ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"],
        ["n", "o", "p", "q", "r", "s", "t", "u", "v", "w"],
        ["A", "B", "C", "D", "E", "F", "G", "H", "J", "K"],
        ["N", "P", "Q", "R", "S", "T", "U", "V", "W", "X"],
        ["k", "m", "x", "y", "z", "L", "M", "Y", "Z"],
        ["2", "3", "4", "5", "6", "7", "8", "9"],
        ["!", "@", "#", "$", "%", "^", "&", "*", "(", ")"],
        ["~", "_", "+", "{", "}", ":", ">", "?", "|"]
    ];

	function xdst() {
        var pwd = [];
        //随机生成密码长度8-16
        var len = randomNum(8, 16);
        var len = 9;
        //循环密码长度
        for (var i = 0; i < signArray_xdst.length; i++) {
            var tmpArray = signArray_xdst[i];
            var signIndex = Math.floor(Math.random() * tmpArray.length);
            pwd.push(tmpArray[signIndex]);
        }
        for (var i = 0; i < len - signArray_xdst.length; i++) {
            var indexNei = Math.floor(Math.random() * signArray_xdst.length);
            var tmpArray = signArray_xdst[indexNei];
            var signIndex = Math.floor(Math.random() * tmpArray.length);
            pwd.push(tmpArray[signIndex]);
		}
		pwd.shuffle();
		document.getElementById("password").innerHTML = pwd.join("");
	}

	
	var signArray_s = [
		["0", "1", "2"],
		["3", "5", "6"],
		["7", "8", "9"]
	];

	function s() {
        var pwd = [];
        //随机生成密码长度8-16
        var len = randomNum(8, 16);
        var len = 6;
        //循环密码长度
        for (var i = 0; i < signArray_s.length; i++) {
            var tmpArray = signArray_s[i];
            var aaa = Math.random() * tmpArray.length;
            console.log("aaa]" + aaa);
            //向下取整正好是同等概率每段数字下标的位置
            var signIndex = Math.floor(aaa);
            console.log("signIndex]" + signIndex)
            pwd.push(tmpArray[signIndex]);
        }
        for (var i = 0; i < len - signArray_s.length; i++) {
			var indexNei = Math.floor(Math.random() * signArray_s.length);
			var tmpArray = signArray_s[indexNei];
			var signIndex = Math.floor(Math.random() * tmpArray.length);
			pwd.push(tmpArray[signIndex]);
		}
		pwd.shuffle();
		document.getElementById("password").innerHTML = pwd.join("");
	}

	
	var signArray_xds = [ 57
		["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"],
		["n", "o", "p", "q", "r", "s", "t", "u", "v", "w"],
		["A", "B", "C", "D", "E", "F", "G", "H", "J", "K"],
		["N", "P", "Q", "R", "S", "T", "U", "V", "W", "X"],
		["k", "m", "x", "y", "z", "L", "M", "Y", "Z"],
		["2", "3", "4", "5", "6", "7", "8", "9"],
	];

	function xds() {
        var pwd = [];
        //随机生成密码长度8-16
        var len = randomNum(8, 16);
        var len = 9;
        //循环密码长度
        for (var i = 0; i < signArray_xds.length; i++) {
            var tmpArray = signArray_xds[i];
            var signIndex = Math.floor(Math.random() * tmpArray.length);
            pwd.push(tmpArray[signIndex]);
        }
        for (var i = 0; i < len - signArray_xds.length; i++) {
            var indexNei = Math.floor(Math.random() * signArray_xds.length);
            var tmpArray = signArray_xds[indexNei];
            var signIndex = Math.floor(Math.random() * tmpArray.length);
            pwd.push(tmpArray[signIndex]);
		}
		pwd.shuffle();
		document.getElementById("password").innerHTML = pwd.join("");
	}


    function randomNum(min, max) {
		return Math.floor(Math.random() * (max - min + 1) + min);
	}

	Array.prototype.shuffle = function () {
		let arr = this,
				temp,
				length = arr.length;
		for (let i = 0; i < arr.length - 1; i++) {
			let index = Math.floor(Math.random() * (length--));
			temp = arr[index];
			arr[index] = arr[length];
			arr[length] = temp;
		}
		return arr;
	};

</script>
</body>
</html>
